import {createRouter, createWebHistory} from 'vue-router'

import Layout from "@/layout/index.vue"

export const menuRoutes = [
    {
        path: '/knowledge',
        name: "knowledge",
        meta: {title: "知识库"},
        component: () => import("@k/knowledge/index.vue")
    }
]

export const constantRoutes = [
    {
        path: '',
        component: Layout,
        redirect: "index",
        children: [
            {
                path: 'index',
                name: 'index',
                component: () => import("@/views/index.vue"),
            },
            ...menuRoutes.map(item => {
                return {
                    ...item,
                    path: item.path.replace(/^\//, '') // 移除前导斜杠
                }
            })
        ]
    }, {
        path: "/login",
        name: "login",
        component: () => import("@/views/login/index.vue"),
    }
]

export const router = createRouter({
    history: createWebHistory(),
    routes: constantRoutes,
})


router.addRoute(menuRoutes)
